﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using He.API.WeiXin;
using He.Common;

namespace He.Web.api.weixin
{
    public partial class return_url : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string code = InputUtil.Get("code");
            if (string.IsNullOrEmpty(code))
            {
                Response.Write("您未同意授权！");
                return;
            }

            UserInfo user = Oauth.GetUserInfo(code);
            //TODO 增加会员信息
            BLL.member bll = new BLL.member();

            if (!bll.Exists(user.openid) && !string.IsNullOrEmpty(user.openid))
            {
                Model.member member = new Model.member();
                member.user_name = user.openid;
                member.user_pwd = StringHelper.GeneratePassword(8);
                member.nickname = user.nickname;
                member.sex = UserInfo.GetSex(user.sex);
                member.city = user.city;
                member.province = user.province;
                member.figure_url = user.headimgurl;
                member.reg_time = DateTime.Now.ToString();
                member.status = 2;
                bll.Add(member);
            }
        }
    }
}